%h2{:class=>"content_header"} #{t(:submit_new_video_header)}

.user_info_zone
  =t(:video_submit_info, :points=>@current_user.active_campaign.points_submit_content)
%h1
  =t(:campaign_how_to_win_more_title)

%p
  .action_required
    =link_to t(:campaign_invite_now_friends_to_act_on_content), publishs_stream_to_vote_comment_url(@current_user)
%p
  =image_tag("icon_like.gif")
  =t(:campaign_invite_friends_to_vote_content_win_points,:points=>@current_user.active_campaign.points_content_voted)


%p
  =image_tag("icon_comment.gif")
  =t(:campaign_invite_friends_to_comment_content_win_points,:points=>@current_user.active_campaign.points_content_commented)

%h2
  =t(:campaign_how_to_win_actions_from_you_title)
%p
  =image_tag("icon_friends.gif")
  =t(:campaign_invite_friends_win_points,:points=>@current_user.active_campaign.points_invite_friends)
%p
  =image_tag("icon_comment.gif")
  =t(:campaign_comment_content_win_points,:points=>@current_user.active_campaign.points_comment_content)
%p
  =image_tag("icon_like.gif")
  =t(:campaign_vote_content_win_points,:points=>@current_user.active_campaign.points_vote_content)



.fb_form_container
  %h2 #{t(:submit_new_video_form_header)}
  -facebook_form_for (:video, @video, :url=>user_videos_path(user_session.user_id)) do |form|
    =form.error_messages
    
    =form.text_field :url    
    =form.text_field :title
    =form.text_area :description
    =form.buttons t(:submit_video)
    
  %h2=t(:video_previewer)
  #loading_indicator{:style=>"display:none"}
    =image_tag("ajax-loader.gif")
  .inline_error_message{:id=>"new_video_errors"}
  #new_video_previewer
  
%script{:type => "text/javascript", :charset => "utf-8"}    
  var serverUrl = '#{discover_video_info_url({:canvas=>false})}/';
  :plain
  
    url_input = $('video_url');
    url_input.addEventListener('change', function() {
       updatevideoInfo()
    });
    
    function updatevideoInfo() {
      //get the content of URL
      $('loading_indicator').show();
      $('video_title').setValue("");
      $('video_description').setValue("");
      $('new_video_previewer').setTextValue("");
      $('new_video_errors').setTextValue("");
      $('video_title').setDisabled(true);
      $('video_description').setDisabled(true);
      encodedUri = serverUrl+'?url='+encodeURIComponent(url_input.getValue());
      Ajax.Load('JSON', serverUrl,
      {
        success:
          function(result){
            updateVideo(result)
          },
          begin: function(){}, 
          complete:function(){responseLoaded()}
      },{'url':url_input.getValue()});
    }
    function responseLoaded() {
      $('loading_indicator').hide();
      $('video_title').setDisabled(false);
      $('video_description').setDisabled(false);
    
    }
    
    function updateVideo(response) {
      if (response.error) {
        $('new_video_errors').setTextValue(response.error);
      } else {
        $('video_title').setValue(response.title);
        $('video_description').setValue(response.description);
        $('new_video_previewer').setInnerFBML(response.fbml_video_code);
      }
    }